package com.codinghero.zqlb.match;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.codinghero.util.DateUtils;
import com.codinghero.util.StringUtils;

public class MatchUtils {
	public static Entry<String, Integer> contains(
			Map<String, Integer> map, String str) {
		Iterator<Entry<String, Integer>> iter = map.entrySet().iterator();
		while (iter.hasNext()) {
			Entry<String, Integer> e = iter.next();
			if (str.contains(e.getKey())) {
				return e;
			}
		}
		return null;
	}
	
	public static int isFocused(SoccerMatch match) {
		return match.getTypeFocused() + match.getTeam1Focused()
				+ match.getTeam2Focused();
	}
	
	public static String getBaiduShareShort(SoccerMatch match) {
		
		String startDateStr = DateUtils.getDateStr(match.getStartDate(),
				"M月d日E，HH:mm");
		String startTimeStr = DateUtils.getDateStr(match.getStartDate(),
				"HH:mm");
		
		if (isFocused(match) == 0)
			return startTimeStr;
		final String baiduShareShort = "<div id='bdshare' class='bdshare_t bds_tools get-codes-bdshare' "
				+ "data=\"{'desc':'足球喇叭比赛预告 - 方便您查看最近的体育赛程',"
				+ "'text':'${text}',"
				+ "'comment':'看球不愁了',"
				+ "'pic':'${pic}'}\">"
				+ "<span class='bds_more'>${shareLabel}</span></div>";
		
		// text part
		String teamVs = "";
		if (!StringUtils.isEmpty(match.getTeam1Name())) {
			teamVs = match.getTeam1Name();
			if (!StringUtils.isEmpty(match.getTeam2Name())) {
				teamVs += (" - " + match.getTeam2Name());
			}
		}
		
		String text = startDateStr + match.getTypeName() + " " + teamVs
				+ "❤直播链接-&gt;";
		String result = baiduShareShort.replace("${text}", text);
		
		// pic part
//		if (match.getTypeId() != null && match.getTypeId() == 200)
//			result = result.replace("${pic}", "http://zuqiulaba.sinaapp.com/extend/european_icon.jpg");
//		else
		if (match.getTypeId() != null && match.getTypeId() == 10000)
			result = result.replace("${pic}", "http://zuqiulaba.sinaapp.com/extend/csl_icon.jpg");
		else
			result = result.replace("${pic}", "");
		
		// shareLabel
		return result.replace("${shareLabel}", "收藏&nbsp;" + startTimeStr);
	}
}
